﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using Sprinkles.Tests.TestClasses;
using System.Text;
using System.Collections.Generic;

namespace Sprinkles.Tests.DeploymentHosts
{
    public class DummyHost_C3 : DeploymentHost
    {
        public static bool ALLOW = true;
        protected override bool Include
        {
            get { return (UserContext == "construction-config-1") && ALLOW; }
        }

        private string Qualify(string name)
        {
            return "DummyHost_C3." + name;
        }
        private string Qualify2(string name)
        {
            return "DummyHost_C3.Expression." + name;
        }
        private string Qualify3(string name)
        {
            return "DummyHost_C3.Placeholders." + name;
        }
        private string Qualify4(string name)
        {
            return "DummyHost_C3.Untyped." + name;
        }
        private string Qualify5(string name)
        {
            return "DummyHost_C3.ReferenceStrings." + name;
        }
        private string Qualify6(string name)
        {
            return "DummyHost_C3.ReferenceFutureObjects." + name;
        }
        private string Qualify7(string name)
        {
            return "DummyHost_C3.UntypedReferenceFutureObjects." + name;
        }

        protected override void RegisterDeployments()
        {
            var ourRefs = SetReferenceForUse();

            SetLiterals();
            SetExpressions();
            SetPlaceholders();
            SetUntyped();
            SetReferenceStrings();
            SetReferenceFutureObjects(ourRefs);
            SetUntypedReferenceFutureObjects(ourRefs);
        }

        private List<FutureDeployedObject<StringBuilder>> SetReferenceForUse()
        {
            var result = new List<FutureDeployedObject<StringBuilder>>();
            for (int i = 0; i < 20; i++)
            {
                var item = Register<StringBuilder>()
                    .Name(Qualify("shared." + i))
                    .CreatedBy.Constructor((string a) => new StringBuilder(a))
                    .SetLiteral(i.ToString())
                    .Done();
                result.Add(item);
            }
            return result;
        }
        private void SetLiterals()
        {
            Register<ConstructorTest1>()
                .Name(Qualify("1"))
                .CreatedBy.Constructor((int a) => new ConstructorTest1(a))
                .SetLiteral(1)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("2"))
                .CreatedBy.Constructor((int a, object b) => new ConstructorTest1(a, b))
                .SetLiteral(1)
                .SetLiteral("A")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetLiteral(0)
                .SetLiteral(1)
                .SetLiteral(2)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetLiteral(3)
                .SetLiteral(4)
                .SetLiteral(5)
                .SetLiteral(6)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetLiteral(7)
                .SetLiteral(8)
                .SetLiteral(9)
                .SetLiteral(10)
                .SetLiteral(11)
                .Done();
        }
        private void SetUntyped()
        {
            Register<ConstructorTest1>()
                .Name(Qualify4("1"))
                .CreatedBy.Constructor((int a) => new ConstructorTest1(a))
                .SetUntypedObject(4)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify4("2"))
                .CreatedBy.Constructor((int a, object b) => new ConstructorTest1(a, b))
                .SetUntypedObject(4)
                .SetUntypedObject("Aha")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify4("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetUntypedObject(3)
                .SetUntypedObject(4)
                .SetUntypedObject(5)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify4("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetUntypedObject(6)
                .SetUntypedObject(7)
                .SetUntypedObject(8)
                .SetUntypedObject(9)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify4("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetUntypedObject(10)
                .SetUntypedObject(11)
                .SetUntypedObject(12)
                .SetUntypedObject(13)
                .SetUntypedObject(14)
                .Done();
        }
        private void SetExpressions()
        {
            Register<ConstructorTest1>()
                .Name(Qualify2("1"))
                .CreatedBy.Constructor((int a) => new ConstructorTest1(a))
                .SetExpression("1+1")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify2("2"))
                .CreatedBy.Constructor((int a, object b) => new ConstructorTest1(a, b))
               .SetExpression("1+1")
                .SetExpression("'A'.ToLower()")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify2("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetExpression("0+1")
                .SetExpression("1+1")
                .SetExpression("2+1")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify2("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetExpression("3+1")
                .SetExpression("4+1")
                .SetExpression("5+1")
                .SetExpression("6+1")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify2("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetExpression("7+1")
                .SetExpression("8+1")
                .SetExpression("9+1")
                .SetExpression("10+1")
                .SetExpression("11+1")
                .Done();
        }
        private void SetPlaceholders()
        {
            Register<ConstructorTest1>()
                .Name(Qualify3("1"))
                .CreatedBy.Constructor((int a) => new ConstructorTest1(a))
                .SetPlaceholder("${3}")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify3("2"))
                .CreatedBy.Constructor((int a, object b) => new ConstructorTest1(a, b))
                .SetPlaceholder("${3}")
                .SetPlaceholder("${4}")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify3("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetPlaceholder("${2}")
                .SetPlaceholder("${3}")
                .SetPlaceholder("${4}")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify3("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetPlaceholder("${5}")
                .SetPlaceholder("${6}")
                .SetPlaceholder("${7}")
                .SetPlaceholder("${8}")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify3("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetPlaceholder("${9}")
                .SetPlaceholder("${10}")
                .SetPlaceholder("${11}")
                .SetPlaceholder("${12}")
                .SetPlaceholder("${13}")
                .Done();
        }
        private void SetReferenceStrings()
        {
            Register<ConstructorTest1>()
                .Name(Qualify5("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetReference(Qualify("shared.4"))
                .SetReference(Qualify("shared.5"))
                .SetReference(Qualify("shared.6"))
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify5("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetReference(Qualify("shared.7"))
                .SetReference(Qualify("shared.8"))
                .SetReference(Qualify("shared.9"))
                .SetReference(Qualify("shared.10"))
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify5("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetReference(Qualify("shared.11"))
                .SetReference(Qualify("shared.12"))
                .SetReference(Qualify("shared.13"))
                .SetReference(Qualify("shared.14"))
                .SetReference(Qualify("shared.15"))
                .Done();
        }
        private void SetReferenceFutureObjects(List<FutureDeployedObject<StringBuilder>> ourRefs)
        {
            Register<ConstructorTest1>()
                .Name(Qualify6("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetReference(ourRefs[0])
                .SetReference(ourRefs[1])
                .SetReference(ourRefs[2])
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify6("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetReference(ourRefs[3])
                .SetReference(ourRefs[4])
                .SetReference(ourRefs[5])
                .SetReference(ourRefs[6])
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify6("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetReference(ourRefs[7])
                .SetReference(ourRefs[8])
                .SetReference(ourRefs[9])
                .SetReference(ourRefs[10])
                .SetReference(ourRefs[11])
                .Done();
        }
        private void SetUntypedReferenceFutureObjects(List<FutureDeployedObject<StringBuilder>> ourRefs)
        {
            Register<ConstructorTest1>()
                .Name(Qualify7("A"))
                .CreatedBy.Constructor((object a, object b, object c) => new ConstructorTest1(a, b, c))
                .SetReferenceUntyped(ourRefs[7])
                .SetReferenceUntyped(ourRefs[8])
                .SetReferenceUntyped(ourRefs[9])
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify7("B"))
                .CreatedBy.Constructor((object a, object b, object c, object d) => new ConstructorTest1(a, b, c, d))
                .SetReferenceUntyped(ourRefs[10])
                .SetReferenceUntyped(ourRefs[11])
                .SetReferenceUntyped(ourRefs[12])
                .SetReferenceUntyped(ourRefs[13])
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify7("C"))
                .CreatedBy.Constructor((object a, object b, object c, object d, object e) => new ConstructorTest1(a, b, c, d, e))
                .SetReferenceUntyped(ourRefs[14])
                .SetReferenceUntyped(ourRefs[15])
                .SetReferenceUntyped(ourRefs[16])
                .SetReferenceUntyped(ourRefs[17])
                .SetReferenceUntyped(ourRefs[18])
                .Done();
        }
    }
}
